package bankofficegrepper

/**
 * Created by IntelliJ IDEA.
 * User: janexie
 * Date: 2010-11-28
 * Time: 15:30:52
 * To change this template use File | Settings | File Templates.
 */

class CMBBankInfoResolver extends BankInfoResolver {
  def resolveData(def source) {
    def records = new XmlSlurper().parseText(source)
    List list = []
    def province = records.body.form.table[1].tbody.tr.td.table.tbody.tr[1].td.span[1].select.find {it.@name == "ddlProvince"}.option.findAll {it.@selected == "selected"}.text()
    def city = records.body.form.table[1].tbody.tr.td.table.tbody.tr[1].td.span[1].select.find {it.@name == "ddlCity"}.option.findAll {it.@selected == "selected"}.text()
    if (province == '') {
      province = city
    }
    def bankInfoRows = records.body.form.table[1].tbody.tr.td.table[2].tbody.tr.td.table.tbody.tr
    if (bankInfoRows.size() == 0) {
      println 'rows is 0'
      return []
    }
    bankInfoRows = bankInfoRows[1..bankInfoRows.size() - 2]

    bankInfoRows.each {
      def bankInfoRow = it.td
      BankInfo info = new BankInfo();
      info.province = province
      info.city = city
      info.name = bankInfoRow[0]
      info.address = bankInfoRow[1]
      info.telephoneNo = bankInfoRow[2]
      info.serviceTime = bankInfoRow[3]
      info.bankName = 'CMB'
      list += info
    }
    return list
  }
}